package com.bulls.demo.hrmsdemo.service;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import com.bulls.demo.hrmsdemo.db.Vendor;
import com.bulls.demo.hrmsdemo.ib.VendorMasterLogic;

public class VendorMasterService {
	
	   private static EntityManager em=null;

	    EntityManagerFactory emf;
	    
	    public EntityManager getEntityManager(){


	        emf = Persistence.createEntityManagerFactory("pu");
	        if(emf == null){
	        	System.out.println("em is null");
	        }else{
	        	System.out.println("em is created");
	        }
	        em = emf.createEntityManager();
	        System.out.println("em is created="+em);
			return em;
	    }

		public Vendor save(Vendor vendor){
			vendor = VendorMasterLogic.save(vendor, getEntityManager());
			return vendor;
		}
		
		public Vendor search(String string){
			Vendor vendor = VendorMasterLogic.search(string, getEntityManager());
			return vendor;
		}
		
		public boolean delete(long vendorSK){
			boolean boo = VendorMasterLogic.delete(vendorSK, getEntityManager());
			return boo;
		}
}
